package fi.pyppe.android.gps.util;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.location.Location;

/**
 * Utilities.
 * 
 * @author Pyppe
 */
public class Utilities {
  
  public static void showMessageDialog(String title, String message, Context className) {
    AlertDialog messageDialog = new AlertDialog.Builder(className).create();
    messageDialog.setTitle(title);
    messageDialog.setMessage(message);
    messageDialog.setButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
        return;
      }
    });
    messageDialog.show();
  }
  
  
  public static String escapeForXml(String str) {
    str = str.replace("<", "&gt;");
    str = str.replace(">", "&lt;");
    str = str.replace("&", "&amp;");
    str = str.replace("\"", "&quot;");
    return str;
  }


  public static String getDirectionArrow(Location location) {
    if (!location.hasBearing()) {
      return "-";
    }
    float bearingDegrees = location.getBearing();
    String direction;
    if (bearingDegrees > 348.75 || bearingDegrees <= 11.25) {
      direction = "\u2191"; // North
    } else if (bearingDegrees > 11.25 && bearingDegrees <= 78.75) {
      direction = "\u2197"; // North-east
    } else if (bearingDegrees > 78.75 && bearingDegrees <= 101.25) {
      direction = "\u2192"; // East
    } else if (bearingDegrees > 101.25 && bearingDegrees <= 168.75) {
      direction = "\u2198"; // South-east
    } else if (bearingDegrees > 168.75 && bearingDegrees <= 191.25) {
      direction = "\u2193"; // South
    } else if (bearingDegrees > 191.25 && bearingDegrees <= 258.75) {
      direction = "\u2199"; // South-west
    } else if (bearingDegrees > 258.75 && bearingDegrees <= 281.25) {
      direction = "\u2190"; // West
    } else if (bearingDegrees > 281.25 && bearingDegrees <= 348.75) {
      direction = "\u2196"; // North-west
    } else {
      direction = "-";
    }
    return direction;
  }

}
